import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Login from "@/views/Login/index.vue";
import Home from "@/views/Home.vue";
import Userma from "@/views/Userma.vue";
import Label from "@/views/Label.vue";
import Essay from "@/views/Essay.vue";
import Message from "@/views/Message.vue";
import Review from "@/views/Review.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/home",
    component: Home,
    children: [
      {
        path: "",
        redirect: "/home/userman",
      },
      {
        path: "userman",
        component: Userma,
      },
      {
        path: "label",
        component: Label,
      },
      {
        path: "essay",
        component: Essay,
      },
      {
        path: "message",
        component: Message,
      },
      {
        path: "review",
        component: Review,
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.path === "/login") {
    localStorage.removeItem("jiang_mange_token");
  }
  next();
});
export default router;
